home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / JAVA / UTIL / Observable.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  1.2 KB  |  85 lines

  1. package java.util;
  2.  
  3. public class Observable {
  4.    private boolean changed = false;
  5.    private Object obs;
  6.  
  7.    public synchronized void addObserver(Observer var1) {
  8.       if (this.obs != null) {
  9.          if (this.obs instanceof ObserverList) {
  10.             if (!((ObserverList)this.obs).contains(var1)) {
  11.                ((ObserverList)this.obs).addElement(var1);
  12.                return;
  13.             }
  14.  
  15.             return;
  16.          }
  17.  
  18.          if (this.obs != var1) {
  19.             ObserverList var2 = new ObserverList();
  20.             ((Vector)var2).addElement(this.obs);
  21.             ((Vector)var2).addElement(var1);
  22.             this.obs = var2;
  23.             return;
  24.          }
  25.       } else {
  26.          this.obs = var1;
  27.       }
  28.  
  29.    }
  30.  
  31.    public synchronized void deleteObserver(Observer var1) {
  32.       if (this.obs == var1) {
  33.          this.obs = null;
  34.       } else {
  35.          if (this.obs != null && this.obs instanceof ObserverList) {
  36.             ((ObserverList)this.obs).removeElement(var1);
  37.          }
  38.  
  39.       }
  40.    }
  41.  
  42.    public void notifyObservers() {
  43.       this.notifyObservers((Object)null);
  44.    }
  45.  
  46.    public synchronized void notifyObservers(Object var1) {
  47.       if (this.hasChanged()) {
  48.          if (this.obs != null) {
  49.             if (this.obs instanceof ObserverList) {
  50.                ((ObserverList)this.obs).notifyObservers(this, var1);
  51.             } else {
  52.                ((Observer)this.obs).update(this, var1);
  53.             }
  54.          }
  55.  
  56.          this.clearChanged();
  57.       }
  58.  
  59.    }
  60.  
  61.    public synchronized void deleteObservers() {
  62.       this.obs = null;
  63.    }
  64.  
  65.    protected synchronized void setChanged() {
  66.       this.changed = true;
  67.    }
  68.  
  69.    protected synchronized void clearChanged() {
  70.       this.changed = false;
  71.    }
  72.  
  73.    public synchronized boolean hasChanged() {
  74.       return this.changed;
  75.    }
  76.  
  77.    public synchronized int countObservers() {
  78.       if (this.obs != null) {
  79.          return this.obs instanceof ObserverList ? ((ObserverList)this.obs).size() : 1;
  80.       } else {
  81.          return 0;
  82.       }
  83.    }
  84. }
  85.